﻿/// <reference path="../kendo.web-vsdoc.js" />
$(document).ready(
 function () {
     $("#btnListar").click(function () {
         $("#ListarClientes").empty();
         var nombre = $("#txtBusqueda").val();
         $.getJSON("/Cliente/ClienteListarJSON", { busqueda: nombre }, function (resultado) {
             $("#ListarClientes").kendoGrid({
                 dataSource: {
                     data: resultado,
                     pageSize: 3
                 },
                 selectable: "multiple",
                 grupable: true,
                 sortable: true,
                 pageable: true,
                 width: 500,
                 columns: [
                       { field: "ID", width: 30, title: "ID" }
                     , { field: "Cliente", width: 150, title: "Nombres" }
                     , { field: "Documento", width: 100, title: "Documento" }
                 ]
             });
             var ListarClientes = $("#ListarClientes").data("kendoGrid");
             ListarClientes.bind("change", grid_change);
         });
     });
     function grid_change(e) {        
         var grid = $("#ListarClientes").data("kendoGrid");
         var row = grid.select();
         //var row = this.select();
         var uid = row.data("uid");
         var Cliente = $('[data-uid="' + uid + '"] td:first').text();
         //alert(tr_first);
         //var url = "@Url.Action("Show", "Info", new { id="param-id", name="param-name" })";
         var url = "/Cliente/Index/" + null + "?Cliente=" + Cliente;
         window.location.href = url;
         //$("#result").load(url);
         //url = url.replace("param-id", Cliente);

         //var selectedCells = this.select();
         //var selectedDataItems = [];
         //for (var i = 0; i < selectedCells.length; i++) {
         //    var dataItem = this.dataItem(selectedCells[i].parentNode);
         //    if ($.inArray(dataItem, selectedDataItems) < 0) {
         //        selectedDataItems.push(dataItem);
         //    }
         //}
         // selectedDataItems contains all selected data items
     }
 });